package com.zr.controller.dispatch;

import com.github.pagehelper.PageInfo;
import com.zr.service.dispatch.DispatchAbnormalRecordService;
import com.zr.utils.AjaxResult;
import com.zr.vo.dispatch.DispatchAbnormalRecord;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author 杜雨萌
 * @date 2022/10/29
 * @version 2022.1
 */
@RestController
@RequestMapping("/dispatch/abnormal")
public class DispatchAbnormalRecordController {


    @Resource
    private DispatchAbnormalRecordService dispatchAbnormalRecordService;

    /**
     * 得到异常记录单
     *
     * @param dispatchAbnormalRecord
     * @return
     * @author 杜雨萌
     */
    @PostMapping("list")
    public AjaxResult list(@RequestBody DispatchAbnormalRecord dispatchAbnormalRecord) {
        PageInfo<DispatchAbnormalRecord> pageInfo = dispatchAbnormalRecordService.list(dispatchAbnormalRecord);
        return AjaxResult.success(200, "查询成功", pageInfo);
    }

    /**
     * 获得状态列表
     *
     * @return
     * @author 杜雨萌
     */
    @PostMapping("statusList")
    public AjaxResult statusList() {
        return AjaxResult.success(200, "查询成功", dispatchAbnormalRecordService.statusList());
    }

    /**
     * 获得受理结果列表
     *
     * @return
     * @author 杜雨萌
     */
    @PostMapping("acceptResultList")
    public AjaxResult acceptResultList() {
        return AjaxResult.success(200, "查询成功", dispatchAbnormalRecordService.acceptResultList());
    }


    /***
     * 获取近6个月异常占比信息
     * @return
     */
    @PostMapping("/getAbnormalHalfYear")
    public AjaxResult getAbnormalHalfYear() {

        return AjaxResult.success(200, "查询成功", dispatchAbnormalRecordService.getAbnormalHalfYear());
    }

    ;

    /**
     * 更新异常表
     *
     * @param dispatchAbnormalRecord
     * @return
     * @author 杜雨萌
     */
    @PostMapping("update")
    public AjaxResult update(@RequestBody DispatchAbnormalRecord dispatchAbnormalRecord) {
        return AjaxResult.success(200, "更新成功", dispatchAbnormalRecordService.update(dispatchAbnormalRecord));
    }

    /**
     * 查询当前调度单异常信息
     *
     * @param ticketId
     * @return
     * @author 陈鹏
     */
    @RequestMapping("/listByDispatch/{ticketId}")
    public AjaxResult listByDispatch(@PathVariable("ticketId") String ticketId) {
        List<DispatchAbnormalRecord> list = dispatchAbnormalRecordService.listByDispatch(ticketId);
        return AjaxResult.success(200, "查询成功", list);
    }
}
